package com.lagou;

import com.lagou.bean.CatComsumerComponet;
import com.lagou.bean.ComsumerComponet;
import com.lagou.bean.DogComsumerComponet;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.concurrent.*;

public class AnnotationConsumerMain  {
    public static void main(String[] args) throws  Exception {
        System.out.println("-------------");
        AnnotationConfigApplicationContext   context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        // 获取消费者组件
        ComsumerComponet  service = context.getBean(ComsumerComponet.class);

        CatComsumerComponet  catService = context.getBean(CatComsumerComponet.class);

        DogComsumerComponet  dogService = context.getBean(DogComsumerComponet.class);

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 2, TimeUnit.SECONDS, new LinkedBlockingQueue<>(2000));

        while(true){
            threadPoolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(300l);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    String  hello = service.sayHello("world");
//                    System.out.println("result:"+hello);

                    String  cathello = catService.sayHello("world");
//                    System.out.println("result:"+cathello);

                    String  doghello = dogService.sayHello("world");
//                    System.out.println("result:"+doghello);
                }
            });
        }
    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static  class  ConsumerConfiguration{

    }
}
